package com.fyy.im.server.handler;

import com.fyy.im.message.GChatRequestMessage;
import com.fyy.im.message.GChatResponseMessage;
import com.fyy.im.server.session.GroupSessionFactory;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.List;

/**
 * @Author fyy
 * @Description
 * @Date 2021/5/12 14:58
 */
@ChannelHandler.Sharable
public class GroupChatRequestMessageHandler extends SimpleChannelInboundHandler<GChatRequestMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GChatRequestMessage msg) throws Exception {
        String groupName = msg.getGroupName();
        List<Channel> channels = GroupSessionFactory.getGroupSession().getMembersChannel(groupName);
        for (Channel channel : channels) {
            //群发
            channel.writeAndFlush(new GChatResponseMessage(msg.getFrom(),msg.getContent()));
        }
    }

}
